﻿function ChangeField(myField, myFieldStyle, myLabel, myLabelStyle) {
    myField.className = myFieldStyle;
    document.getElementById(myLabel).className = myLabelStyle;
}
function ShowEmptyMessage(textBox, message, cssclass) {
    if (textBox != null) {
        if (textBox.value == "" || textBox.value == message) {
            textBox.value = message;
            textBox.className = cssclass;
        }
    }
}
function HideEmptyMessage(textBox, message, cssclass) {
    if (textBox != null) {
        if (textBox.value == message) {
            textBox.value = "";
            textBox.className = cssclass;
        }
    }
}
function BlurPhone(txtbox) {
    txtbox.value = txtbox.value.replace(/\D*/g, "");
    if (txtbox.value.length > 0) {
        txtbox.value = "(" + txtbox.value;
    }
    if (txtbox.value.length >= 4) {
        txtbox.value = txtbox.value.substr(0, 4) + ") " + txtbox.value.substr(4, txtbox.value.length - 4);
    }
    if (txtbox.value.length >= 9) {
        txtbox.value = txtbox.value.substr(0, 9) + "-" + txtbox.value.substr(9, txtbox.value.length - 9);
    }
    if (txtbox.value.length > 14) {
        txtbox.value = txtbox.value.substr(0, 14);
    }
}
function FormatPhone(txtbox, e) {
    var myCharCode;
    if (window.ActiveXObject) {
        myCharCode = e.keyCode;
        if (e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 46) {
            return true;
        }
    }
    else {
        myCharCode = e.which;
        if (e.which == 8 || e.which == 9 || e.which == 46) {
            return true;
        }
    }
    if (!IsAllowableCode(myCharCode)) {
        if (myCharCode == 13) {
            e.returnValue = 13;
            return true;
        }
        else {
            e.returnValue = 0;
            return false;
        }

    }
    else if (txtbox.value.length >= 14) {
        e.returnValue = 0;
        return false;
    }
    else {
        txtbox.value = txtbox.value.replace(/\D*/g, "");

        if (txtbox.value.length >= 0) {
            txtbox.value = "(" + txtbox.value;
        }

        if (txtbox.value.length >= 4) {
            txtbox.value = txtbox.value.substr(0, 4) + ") " + txtbox.value.substr(4, txtbox.value.length - 4);
        }

        if (txtbox.value.length >= 9) {
            txtbox.value = txtbox.value.substr(0, 9) + "-" + txtbox.value.substr(9, txtbox.value.length - 9);
        }
    }
}
function IsAllowableCode(c) {
    if ((c >= 48) && (c <= 58)) {
        return true;
    }
    else if ((c >= 96) && (c <= 105)) {
        return true;
    }
    else {
        return false;
    }
}
var SentItemHash;
function RaiseOnKeyUpEvent(elem, emptyMessage, delayMS) {
    if (!SentItemHash) {
        SentItemHash = new Object;
    }
    if (elem.value != emptyMessage) {
        setTimeout("SendOnKeyUpEventRequest('" + elem.value + "','" + elem.id + "')", delayMS);
    }
}
function SendOnKeyUpEventRequest(valueWhenSent, id) {
    var elem = document.getElementById(id);
    if (valueWhenSent == elem.value) {
        if (!SentItemHash[elem.id]) {
            SentItemHash[elem.id] = "";
        }
        if (elem.value != SentItemHash[elem.id]) {
            SentItemHash[elem.id] = elem.value;
            __doPostBack(elem.id, 'OnKeyUpEvent');
        }
    }
}
